<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\store\controller;

use library\Controller;
use library\tools\Data;
use think\Db;
use app\store\model\Common;
/**
 * 订单
 * Class Documentlist
 * @package app\store\controller
 */
class YiOrder extends Controller
{
    /**
     * 指定数据表
     * @var string
     */
    protected $table = 'StoreYinuoOrder';
    protected $table1 = 'store_yinuo_order';

    /**
     * 订单
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index()
    {
        $this->title = '订单';
        $this->user_list = Db::table("store_member")->field("id,username")->select();
        $this->car_list = Db::table("store_car")->field("id,name")->select();
        $this->station_list = Db::table("store_power_station")->field("id,name")->select();
        $this->park_list = Db::table("store_park")->field("id,name")->select();
        $this->device_list = Db::table("store_device")->field("id,name")->select();

        $query = $this->_query($this->table)->like('order_no')->equal("user_id,car_id,member_id,status,type,station_id,park_id,device_id");
        $query->dateBetween('create_at')->where("delete_time is null")->order('id desc')->page();
    }

    /**
     * 数据列表处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function _index_page_filter(&$data)
    {
        foreach ($data as &$vo) {
            $u_id = $vo['user_id'];
            $member_id = $vo['member_id'];
            $car_id = $vo['car_id'];

            $station_id = $vo['station_id'];
            $park_id = $vo['park_id'];
            $device_id = $vo['device_id'];

            $vo['user'] = Db::table("store_member")->where("id=$u_id")->find();
            $vo['member'] = Db::table("store_member")->where("id=$member_id")->find();
            $vo['car'] = Db::table("store_car")->where("id=$car_id")->find();

            $vo['station'] = Db::table("store_power_station")->where("id=$station_id")->find();
            $vo['park'] = Db::table("store_park")->where("id=$park_id")->find();
            $vo['device'] = Db::table("store_device")->where("id=$device_id")->find();

            if($vo['status']==1){  $vo['status_r'] = '<span style="color: dodgerblue;font-weight: bold">预约充电/停车</span>'; }
            if($vo['status']==2){  $vo['status_r'] = '<span style="color: red;font-weight: bold">放行后 已预约</span>'; }
            if($vo['status']==3){  $vo['status_r'] = '<span style="color: orangered">充电/停车中</span>'; }
            if($vo['status']==4){  $vo['status_r'] = '<span style="color: gray">充电/停车完成（待支付）</span>'; }
            if($vo['status']==5){  $vo['status_r'] = '<span style="color: yellowgreen">已支付（待评论）</span>'; }
            if($vo['status']==6){  $vo['status_r'] = '<span style="color: green">已评论（全部完成）</span>'; }
            if($vo['status']==0){  $vo['status_r'] = '<span style="color: black;font-weight: bold">已取消</span>'; }


            if($vo['type']==1){  $vo['type_r'] = '<span style="color: dodgerblue;font-weight: bold">预约充电</span>'; }
            if($vo['type']==2){  $vo['type_r'] = '<span style="color: red;font-weight: bold">预约停车</span>'; }


        }


    }



}
